home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 20 code / AOCE Templates / InfoPageAspect.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-23  |  7.1 KB  |  229 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        InfoPageAspect.c
  3.  
  4.     Contains:    Code resource : this code managed AOCE drag commands.
  5.                 When a record A is dragged on a record B, this code updates record A to store as an attribute 
  6.                 an alias to record B and it updates record B to store an alias of record A.
  7.                 These aliases are displayed in sublists.
  8.                 
  9.     Written by:    Christine Buttin - Apple Computer France
  10.  
  11.     Copyright:    © 1994 by Apple Computer, Inc.
  12.  
  13. */
  14.  
  15. #include <OCE.h>
  16. #include <OCETemplates.h>
  17. #include <Memory.h>
  18. #include <ToolUtils.h>
  19. #include <Packages.h>
  20. #include <events.h>
  21. #include <files.h>
  22. #include <aliases.h>
  23. #include <errors.h>
  24. #include <Stdio.h>
  25. #include <Strings.h>
  26. #include <String.h>
  27. #include <Processes.h>
  28. #include <AERegistry.h>
  29. #include <OCEErrors.h>
  30.  
  31. #ifndef __OCESTANDARDDIRECTORY__
  32. #include <OCEStandardDirectory.h>
  33. #endif
  34.  
  35. #ifndef __OCEAUTHDIR__
  36. #include <OCEAuthDir.h>
  37. #endif
  38.  
  39. #define prChangeRec            kDETFirstDevProperty
  40.  
  41. OSErr DoCommand(DETCallBlock* callBlockPtr);
  42. OSErr DoDropQuery(DETCallBlock* callBlockPtr);
  43. OSErr DoAddRecord(DETCallBlock* callBlockPtr);
  44. void AddRecordAsAttribute (LocalIdentity userLocald,PackedDSSpec* theDSSpec,RecordIDPtr updatedRecord,short refNum,Ptr attrType);
  45.  
  46. // Entry point called by the CE
  47. pascal OSErr KeywordsIP(DETCallBlock* callBlockPtr)
  48. {    
  49. OSErr err = noErr;
  50.  
  51.     if (callBlockPtr->protoCall.target.selector == kDETSelf)
  52.     switch (callBlockPtr->protoCall.reqFunction) {
  53.         case kDETcmdInit:
  54.         // call-for masks
  55.             callBlockPtr->init.newCallFors = kDETCallForCommands + kDETCallForDrops + kDETCallForAttributes;
  56.             break;
  57.  
  58.         case kDETcmdDropQuery:
  59.             err = DoDropQuery(callBlockPtr);
  60.             break;
  61.     
  62.         case kDETcmdPropertyCommand :
  63.             err = DoCommand(callBlockPtr);
  64.             break;
  65.             
  66.         default: 
  67.             err=kDETDidNotHandle;
  68.             break;
  69.     }    
  70.     else err=kDETDidNotHandle;
  71.     
  72.     return err;    
  73.     
  74. }
  75.  
  76. /* Called when an object is dropped onto a record. 
  77.   Just setup a property number (prChangeRec) 
  78.   to be sent to the target aspect.*/
  79. OSErr DoDropQuery(DETCallBlock* callBlockPtr)
  80. {
  81. /* check what is the best guess of the CE regarding the dropped object */
  82.     if (((DETDropQueryBlock*)callBlockPtr)->commandID == kDETAlias) {     /* make an alias of the dragged object */
  83.         ((DETDropQueryBlock*)callBlockPtr)->copyToHFS = false;
  84.         ((DETDropQueryBlock*)callBlockPtr)->commandID = prChangeRec;
  85.         return noErr;
  86.         }
  87.     else 
  88.         //((DETDropQueryBlock*)callBlockPtr)->commandID = kDETDoNothing;
  89.         return kDETDidNotHandle;
  90. }
  91.  
  92.  
  93. /* Called when the CE sends a property command. 
  94.    We check it's the property we expect. */
  95. OSErr DoCommand(DETCallBlock* callBlockPtr)
  96. {
  97.     OSErr err = noErr;
  98.     
  99.     /* check if called for the prChangeRec command */
  100.     switch(((DETPropertyCommandBlock*)callBlockPtr)->property)
  101.         {
  102.         case prChangeRec :
  103.             err = DoAddRecord(callBlockPtr);
  104.             break;
  105.         default :
  106.             return kDETDidNotHandle;
  107.             break;
  108.         }
  109.     return err;
  110. }
  111.  
  112. /* This function adds an attribute as a DSSpec to a record */
  113. void AddRecordAsAttribute(LocalIdentity userLocald,PackedDSSpec* theDSSpec,RecordIDPtr updatedRecord,short refNum,Ptr attrType)
  114. {
  115.     OSErr             err;
  116.     Attribute        theAttribute;
  117.     DirParamBlock    dspb;
  118.     AttributeType    kwRType;
  119.  
  120.     /* prepare the attribute, set up its type and the date within the attribute */
  121.     OCECToRString (attrType,smRoman,(RString *) &kwRType,kAttributeTypeMaxBytes);
  122.     theAttribute.attributeType = kwRType;
  123.     theAttribute.value.tag = typePackedDSSpec;
  124.     theAttribute.value.dataLength = theDSSpec->dataLength+sizeof(theDSSpec->dataLength);
  125.     theAttribute.value.bytes = (Ptr) theDSSpec;
  126.     
  127.     /* prepare the parameter block used by the Catalog Manager to add an attribut*/
  128.     dspb.addAttributeValuePB.ioCompletion = nil;
  129.     *(long *)&dspb.addAttributeValuePB.serverHint = nil;
  130.     dspb.addAttributeValuePB.dsRefNum = refNum;                /* refnum of a personal catalog */
  131.     dspb.addAttributeValuePB.identity = userLocald;
  132.     dspb.addAttributeValuePB.aRecord = updatedRecord;            /* record to be modified */
  133.     dspb.addAttributeValuePB.attr = &theAttribute;            /* attribute to be added */
  134.     dspb.addAttributeValuePB.clientData = 0;
  135.     err = DirAddAttributeValue (&dspb,false);
  136. }
  137.  
  138. /* When a record A is dragged on a record B, this function updates record A to store 
  139.  an alias to record B and it updates record B to store an alias of record A.
  140.  Updates occur if records are of the required type. */
  141. OSErr DoAddRecord(DETCallBlock* callBlockPtr)
  142. {
  143.     DETCallBackBlock     cbb,cbb1,cbb2;
  144.     short                 PABrefNum;
  145.     RecordID             targetRID,receivedRID;
  146.     LocalIdentity         userLocalId;
  147.     PackedDSSpec         *targetDSSpec,*droppedDSSpec;
  148.     DSSpec              dsp,dsp1;
  149.     OSErr                err;
  150.     long                 count,i;
  151.     Str255                targetAttrType;
  152.     Str255                droppedAttrType;
  153.  
  154.     #ifdef USER
  155.     Str255                theStr = "ACFC Keywords";
  156.     RString                recType;
  157.     OCECToRString(theStr, smRoman, &recType,kRStringMaxBytes);
  158.     #endif
  159.     
  160.     /* find out target record dsspec */
  161.     cbb.getDSSpec.target.selector = kDETSelf;
  162.     cbb.getDSSpec.reqFunction = kDETcmdGetDSSpec;
  163.     err = CallBackDET(callBlockPtr, &cbb);
  164.     if (err != noErr) 
  165.         return err;
  166.     
  167.     HLock((Handle)cbb.getDSSpec.dsSpec);
  168.     targetDSSpec = *(cbb.getDSSpec.dsSpec);
  169.     /* get record ID */
  170.     PABrefNum = cbb.getDSSpec.refNum;
  171.     userLocalId = cbb.getDSSpec.identity;
  172.     OCEUnpackDSSpec (targetDSSpec,&dsp,&targetRID);
  173.     
  174.     /* find out how many records have been dropped */
  175.     cbb1.getCommandSelectionCount.reqFunction = kDETcmdGetCommandSelectionCount;
  176.     err = CallBackDET(callBlockPtr, &cbb1);
  177.     if (err != noErr) {
  178.         HUnlock((Handle) cbb.getDSSpec.dsSpec);
  179.         DisposeHandle ((Handle) cbb.getDSSpec.dsSpec);
  180.         return err;
  181.         }
  182.     
  183.     count = cbb1.getCommandSelectionCount.count;
  184.  
  185.     for (i = 1; i <= count;i++) {
  186.         /* get the dsspec of dropped record */
  187.         cbb1.getCommandItemN.reqFunction = kDETcmdGetCommandItemN;
  188.         cbb1.getCommandItemN.itemNumber = i;
  189.         cbb1.getCommandItemN.itemType = kDETDSType;    
  190.         err = CallBackDET(callBlockPtr, &cbb1);
  191.         if (err == noErr) {
  192.             HLock((Handle)cbb1.getCommandItemN.item.ds.dsSpec);
  193.             droppedDSSpec = *(cbb1.getCommandItemN.item.ds.dsSpec);
  194.             OCEUnpackDSSpec (droppedDSSpec,&dsp1,&receivedRID);
  195.             /* check type of record */
  196.             #ifdef USER
  197.             if (OCEEqualRString (receivedRID.local.recordType, &recType, kOCERecordType)) {
  198.                 strcpy(targetAttrType,kMemberAttrTypeBody);
  199.                 strcpy(droppedAttrType,"ACFC Alias keyword");
  200.             #else
  201.             if (OCEEqualRString (receivedRID.local.recordType, OCEGetIndRecordType(kUserRecTypeNum), kOCERecordType)) {
  202.                 strcpy(targetAttrType,"ACFC Alias keyword");
  203.                 strcpy(droppedAttrType,kMemberAttrTypeBody);
  204.             #endif
  205.             /* update the target record to set up the dropped record as an attribute of this record */
  206.                 AddRecordAsAttribute (userLocalId,droppedDSSpec,&targetRID,PABrefNum,droppedAttrType);
  207.             /* update the dropped record to set up the target record as an attribute of the dropped record */
  208.                 AddRecordAsAttribute (userLocalId,targetDSSpec,&receivedRID,PABrefNum,targetAttrType);
  209.                 }
  210.             HUnlock((Handle)cbb1.getCommandItemN.item.ds.dsSpec);
  211.             DisposeHandle((Handle)cbb1.getCommandItemN.item.ds.dsSpec);
  212.             }
  213.         else
  214.             break;
  215.         }
  216.         
  217.     if (err == noErr) {
  218.         /* Ask for immediate update */
  219.         cbb2.requestSync.target = ((DETPropertyCommandBlock*)callBlockPtr)->target;
  220.         cbb2.requestSync.reqFunction = kDETcmdRequestSync;
  221.         err = CallBackDET(callBlockPtr, &cbb2);    
  222.         }
  223.     HUnlock((Handle) cbb.getDSSpec.dsSpec);
  224.     DisposeHandle ((Handle) cbb.getDSSpec.dsSpec);
  225.     return err;
  226.  
  227. }
  228.             
  229.